package com.zretc.blog.controller;


import com.zretc.api.pojo.blogModule.dtos.BlogDto;
import com.zretc.api.pojo.blogModule.pojos.BlogComment;
import com.zretc.blog.service.BlogService;
import com.zretc.common.entity.RespResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

@RestController
@RequestMapping("/blog")
public class BlogController {

    @Autowired
    private BlogService blogService;
    @PostMapping("/submit")
    public RespResult submit(@RequestBody BlogDto blogDto){
        return blogService.submit(blogDto);
    }

    @DeleteMapping("/deleteBlog")
    public RespResult deleteBlog(@RequestBody BlogDto blogDto){
        return blogService.deleteBlog(blogDto);
    }

    @GetMapping("/{channel}")
    public RespResult getByChannel(@PathVariable String channel){
        return blogService.getByChannel(channel);
    }

    @GetMapping("/getBlogDetails")
    public RespResult getBlogDetails(@RequestBody BlogDto blogDto){ return blogService.getBlogDetails(blogDto);}

    @PostMapping("/createComment")
    public RespResult createComment(@RequestBody BlogComment toComment, @RequestParam Long blogId, @RequestParam String commentContent){ return blogService.createComment(toComment,blogId,commentContent);}

    @DeleteMapping("/deleteComment")
    public RespResult deleteComment(@RequestBody BlogComment blogComment){ return blogService.deleteComment(blogComment);}

    @PostMapping("/like/{blogId}")
    public RespResult like(@PathVariable Long blogId){
        return blogService.like(blogId);
    }

    @PostMapping("/uploadImages")
    public RespResult uploadImages(@RequestParam MultipartFile[] files){
        return blogService.uploadImages(files);
    }
}
